<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.library.entity.po.BookCopyPO" %>
<%@ page import="com.library.entity.po.PagePO" %>
<%@ page import="com.library.entity.Book" %>
<%@ page import="java.util.List" %>
<%@ page import="com.library.entity.Admin" %>
<%
    List<Book> availableBooks = (List<Book>) request.getAttribute("availableBooks");
    out.println("<!-- 调试: availableBooks size: " + (availableBooks == null ? "null" : availableBooks.size()) + " -->");
%>
<!DOCTYPE html>
<html>
<head>
    <title>图书管理系统 - 书籍副本管理</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        /* 页面整体样式 */
        body {
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
            background-color: #f5f5f5;
        }

        /* 顶部导航栏样式 */
        .header {
            background-color: #f8f9fa;
            padding: 10px 20px;
            border-bottom: 1px solid #e0e0e0;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .header h1 {
            margin: 0;
            font-size: 20px;
            color: #333;
        }

        .user-info {
            display: flex;
            align-items: center;
        }

        .logout-btn {
            margin-left: 15px;
            padding: 5px 10px;
            background-color: #f8f9fa;
            border: 1px solid #ddd;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
            color: #333;
        }

        /* 左侧导航栏样式 */
        .nav-container {
            width: 200px;
            background-color: #f8f9fa;
            float: left;
            min-height: calc(100vh - 50px);
            border-right: 1px solid #e0e0e0;
        }

        .admin-label {
            padding: 15px;
            background-color: #e9ecef;
            font-weight: bold;
            border-bottom: 1px solid #ddd;
        }

        .nav-container ul {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        .nav-container li {
            padding: 15px;
            cursor: pointer;
            border-bottom: 1px solid #e0e0e0;
        }

        .nav-container li:hover {
            background-color: #e9ecef;
        }

        .nav-container li a {
            text-decoration: none;
            color: #333;
            display: block;
        }

        .nav-container li.active {
            background-color: #007bff;
        }

        .nav-container li.active a {
            color: white;
        }

        /* 中间内容区域样式 */
        .content-container {
            margin-left: 200px;
            padding: 20px;
        }

        /* 操作按钮样式 */
        .action-buttons {
            margin-bottom: 20px;
        }

        .btn {
            padding: 8px 15px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            margin-right: 10px;
            text-decoration: none;
            display: inline-block;
        }

        .btn:hover {
            background-color: #0069d9;
        }

        .btn-danger {
            background-color: #dc3545;
        }

        .btn-danger:hover {
            background-color: #c82333;
        }

        /* 搜索框样式 */
        .search-box {
            margin-bottom: 20px;
            display: flex;
        }

        .search-box input {
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px 0 0 4px;
            width: 300px;
        }

        .search-box button {
            padding: 8px 15px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 0 4px 4px 0;
            cursor: pointer;
        }

        /* 表格样式 */
        .copy-table {
            width: 100%;
            border-collapse: collapse;
            background-color: white;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }

        .copy-table th, .copy-table td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #ddd;
        }

        .copy-table th {
            background-color: #f8f9fa;
            font-weight: bold;
        }

        .copy-table tr:hover {
            background-color: #f5f5f5;
        }

        .action-link {
            color: #007bff;
            text-decoration: none;
            margin-right: 10px;
            cursor: pointer;
        }

        .action-link:hover {
            text-decoration: underline;
        }

        .action-link.delete {
            color: #dc3545;
        }

        /* 状态标签样式 */
        .status {
            padding: 4px 8px;
            border-radius: 4px;
            font-size: 12px;
        }

        .status-available {
            background-color: #d4edda;
            color: #155724;
        }

        .status-borrowed {
            background-color: #f8d7da;
            color: #721c24;
        }

        .status-cancelled {
            background-color: #e2e3e5;
            color: #383d41;
        }

        /* 分页样式 */
        .pagination {
            margin-top: 20px;
            display: flex;
            justify-content: center;
        }

        .pagination a {
            padding: 8px 12px;
            margin: 0 5px;
            border: 1px solid #ddd;
            text-decoration: none;
            color: #007bff;
            border-radius: 4px;
        }

        .pagination a:hover {
            background-color: #f5f5f5;
        }

        .pagination a.active {
            background-color: #007bff;
            color: white;
            border-color: #007bff;
        }

        .pagination a.disabled {
            color: #aaa;
            cursor: not-allowed;
            background-color: #f5f5f5;
            border-color: #ddd;
        }

        /* 消息样式 */
        .alert {
            padding: 12px;
            margin-bottom: 20px;
            border-radius: 4px;
        }

        .alert-success {
            background-color: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        .alert-error {
            background-color: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }

        .no-data {
            text-align: center;
            color: #666;
            font-style: italic;
            padding: 40px;
        }

        .page-info {
            text-align: center;
            margin-top: 10px;
            color: #666;
            font-size: 14px;
        }

        /* 弹窗样式 */
        .modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
        }

        .modal-content {
            background-color: #fefefe;
            margin: 10% auto;
            padding: 0;
            border-radius: 8px;
            width: 500px;
            max-width: 90%;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }

        .modal-header {
            padding: 20px;
            background-color: #f8f9fa;
            border-bottom: 1px solid #e0e0e0;
            border-radius: 8px 8px 0 0;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .modal-header h3 {
            margin: 0;
            color: #333;
        }

        .close {
            color: #aaa;
            font-size: 28px;
            font-weight: bold;
            cursor: pointer;
            line-height: 1;
        }

        .close:hover {
            color: #000;
        }

        .modal-body {
            padding: 20px;
        }

        .modal-footer {
            padding: 15px 20px;
            background-color: #f8f9fa;
            border-top: 1px solid #e0e0e0;
            border-radius: 0 0 8px 8px;
            text-align: right;
        }

        /* 表单样式 */
        .form-group {
            margin-bottom: 15px;
        }

        .form-group label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            color: #333;
        }

        .form-group input, .form-group select {
            width: 100%;
            padding: 8px 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
            box-sizing: border-box;
            background-color: white;
        }

        .form-group select {
            cursor: pointer;
        }

        .form-group input:focus, .form-group select:focus {
            outline: none;
            border-color: #007bff;
            box-shadow: 0 0 0 2px rgba(0,123,255,0.25);
        }

        .form-group input::placeholder {
            color: #999;
            font-style: italic;
        }

        .form-group select option {
            padding: 5px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .btn-secondary {
            background-color: #6c757d;
            color: white;
            border: none;
            padding: 8px 15px;
            border-radius: 4px;
            cursor: pointer;
            margin-left: 10px;
        }

        .btn-secondary:hover {
            background-color: #5a6268;
        }

        .error-message {
            color: #dc3545;
            font-size: 12px;
            margin-top: 5px;
        }

        .status-tip {
            color: #dc3545;
            font-size: 12px;
            margin-top: 5px;
        }
    </style>
</head>
<body>
<!-- 顶部导航栏 -->
<div class="header">
    <h1>图书管理系统</h1>
    <div class="user-info">
        欢迎您，<%=((Admin) request.getSession().getAttribute("admin")).getUsername()%>
        <a href="../common?method=logout" class="logout-btn">退出登录</a>
    </div>
</div>

<!-- 左侧导航栏 -->
<div class="nav-container">
    <div class="admin-label">管理端</div>
    <ul>
        <li><a href="../admin?method=adminIndex">首页</a></li>
        <li><a href="../admin/book?method=bookManage">书籍</a></li>
        <li class="active"><a href="../admin/bookcopy?method=bookCopyManage">书籍副本</a></li>
        <li><a href="../admin/payrec?method=fineRecord">学生罚款记录</a></li>
    </ul>
</div>

<!-- 中间内容区域 -->
<div class="content-container">
    <h2>书籍副本管理</h2>

    <!-- 显示操作结果消息 - 修改为从request属性读取而不是参数 -->
    <% String success = (String) request.getAttribute("success"); %>
    <% String error = (String) request.getAttribute("error"); %>

    <% if ("add".equals(success)) { %>
    <div class="alert alert-success">副本添加成功！</div>
    <% } else if ("update".equals(success)) { %>
    <div class="alert alert-success">副本更新成功！</div>
    <% } else if ("delete".equals(success)) { %>
    <div class="alert alert-success">副本注销成功！</div>
    <% } else if ("batchdelete".equals(success)) { %>
    <div class="alert alert-success">批量注销成功！</div>
    <% } %>

    <% if ("param".equals(error)) { %>
    <div class="alert alert-error">参数错误！</div>
    <% } else if ("booknotfound".equals(error)) { %>
    <div class="alert alert-error">该ISBN对应的书籍不存在或未上架！</div>
    <% } else if ("invalidstatus".equals(error)) { %>
    <div class="alert alert-error">状态值无效！</div>
    <% } else if ("borrowedstatus".equals(error)) { %>
    <div class="alert alert-error">新添加的副本不能直接设置为借出状态！</div>
    <% } else if ("addfailed".equals(error)) { %>
    <div class="alert alert-error">添加失败，该条码号可能已存在！</div>
    <% } else if ("updatefailed".equals(error)) { %>
    <div class="alert alert-error">更新失败，请检查副本是否存在！</div>
    <% } else if ("deletefailed".equals(error)) { %>
    <div class="alert alert-error">注销失败，该副本可能已借出或不存在！</div>
    <% } else if ("batchdeletefailed".equals(error)) { %>
    <div class="alert alert-error">批量注销失败！</div>
    <% } else if ("nobatch".equals(error)) { %>
    <div class="alert alert-error">请选择要注销的副本！</div>
    <% } else if ("numberformat".equals(error)) { %>
    <div class="alert alert-error">数字格式错误！</div>
    <% } else if ("system".equals(error)) { %>
    <div class="alert alert-error">系统错误，请稍后重试！</div>
    <% } else if ("notfound".equals(error)) { %>
    <div class="alert alert-error">副本不存在！</div>
    <% } else if ("invalidbarcode".equals(error)) { %>
    <div class="alert alert-error">条码号格式无效！条码号应为6-20位字母数字组合。</div>
    <% } else if ("borrowedcannotchange".equals(error)) { %>
    <div class="alert alert-error">已借出的副本不能修改状态，只能修改位置！</div>
    <% } %>

    <!-- 操作按钮 -->
    <div class="action-buttons">
        <button class="btn" onclick="showAddModal()">添加新副本</button>
        <button class="btn btn-danger" onclick="batchCancel()">批量注销</button>
    </div>

    <!-- 搜索框 -->
    <div class="search-box">
        <form action="${pageContext.request.contextPath}/admin/bookcopy" method="get">
            <input type="hidden" name="method" value="bookCopyManage">
            <input type="text" name="keyword" placeholder="输入书名、副本编号或ISBN搜索..." value="${keyword}">
            <button type="submit">搜索</button>
        </form>
    </div>

    <!-- 书籍副本表格 -->
    <form id="batchForm">
        <table class="copy-table">
            <thead>
            <tr>
                <th><input type="checkbox" id="selectAll" onclick="toggleSelectAll()"></th>
                <th>副本编号</th>
                <th>ISBN</th>
                <th>书名</th>
                <th>状态</th>
                <th>位置</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <%
                PagePO<BookCopyPO> bookCopyPOPagePO = (PagePO<BookCopyPO>) request.getAttribute("bookCopyPOPagePO");
                if (bookCopyPOPagePO != null && bookCopyPOPagePO.getList() != null && !bookCopyPOPagePO.getList().isEmpty()) {
                    for (BookCopyPO bookCopyPO : bookCopyPOPagePO.getList()) {
                        String safePlace = bookCopyPO.getPlace() != null ? bookCopyPO.getPlace().replace("'", "\\'") : "";
                        String bname = bookCopyPO.getBname() != null ? bookCopyPO.getBname() : "未知";
                        String place = bookCopyPO.getPlace() != null ? bookCopyPO.getPlace() : "";
                        String statusHtml = "";
                        if (bookCopyPO.getStatus() == 1) statusHtml = "<span class='status status-available'>可借</span>";
                        else if (bookCopyPO.getStatus() == 0) statusHtml = "<span class='status status-borrowed'>借出</span>";
                        else if (bookCopyPO.getStatus() == 2) statusHtml = "<span class='status status-cancelled'>注销</span>";
                        out.write("<tr>");
                        out.write("<td><input type='checkbox' class='copy-checkbox' name='barCodes' value='" + bookCopyPO.getBarCode() + "'></td>");
                        out.write("<td>" + bookCopyPO.getBarCode() + "</td>");
                        out.write("<td>" + bookCopyPO.getISBN() + "</td>");
                        out.write("<td>" + bname + "</td>");
                        out.write("<td>" + statusHtml + "</td>");
                        out.write("<td>" + place + "</td>");
                        out.write("<td>");
                        if (bookCopyPO.getStatus() != 2) {
                            out.write("<a href=\"javascript:void(0)\" onclick=\"showEditModal('" + bookCopyPO.getBarCode() + "', '" + bookCopyPO.getISBN() + "', '" + safePlace + "', " + bookCopyPO.getStatus() + ")\" class='action-link'>编辑</a>");
                            if (bookCopyPO.getStatus() != 0) {
                                out.write("<a href=\"javascript:void(0)\" onclick=\"cancelCopy('" + bookCopyPO.getBarCode() + "')\" class='action-link delete'>注销</a>");
                            } else {
                                out.write("<span style='color: #ccc;'>已借出</span>");
                            }
                        } else {
                            out.write("<span style='color: #ccc;'>已注销</span>");
                        }
                        out.write("</td>");
                        out.write("</tr>");
                    }
                } else { %>
                <tr>
                    <td colspan="7" class="no-data">暂无数据</td>
                </tr>
                <% } %>
            </tbody>
        </table>
    </form>

    <!-- 分页 -->
    <div class="pagination">
        <%
            if (bookCopyPOPagePO != null) {
                int pageNum = bookCopyPOPagePO.getPageNum();
                int totalPages = bookCopyPOPagePO.getTotalPage();
                String keyword = (String) request.getAttribute("keyword");
                String keywordParam = (keyword != null && !keyword.isEmpty()) ? "&keyword=" + java.net.URLEncoder.encode(keyword, "UTF-8") : "";

                // 上一页链接
                if (pageNum > 1) {
        %>
        <a href="${pageContext.request.contextPath}/admin/bookcopy?method=bookCopyManage&pageNum=<%= pageNum - 1 %><%= keywordParam %>">&laquo;</a>
        <% } else { %>
        <a href="javascript:void(0)" class="disabled">&laquo;</a>
        <% } %>

        <%
            // 显示页码，最多显示5个页码
            int startPage = Math.max(1, pageNum - 2);
            int endPage = Math.min(totalPages, startPage + 4);

            // 调整startPage，确保显示5个页码（如果有足够的页数）
            if (endPage - startPage < 4 && startPage > 1) {
                startPage = Math.max(1, endPage - 4);
            }

            for (int i = startPage; i <= endPage; i++) {
        %>
        <a href="${pageContext.request.contextPath}/admin/bookcopy?method=bookCopyManage&pageNum=<%= i %><%= keywordParam %>" <%= (i == pageNum) ? "class='active'" : "" %>><%= i %></a>
        <% } %>

        <!-- 下一页链接 -->
        <% if (pageNum < totalPages) { %>
        <a href="${pageContext.request.contextPath}/admin/bookcopy?method=bookCopyManage&pageNum=<%= pageNum + 1 %><%= keywordParam %>">&raquo;</a>
        <% } else { %>
        <a href="javascript:void(0)" class="disabled">&raquo;</a>
        <% } %>
        <% } %>
    </div>

    <!-- 分页信息 -->
    <% if (bookCopyPOPagePO != null) { %>
    <div class="page-info">
        共 <%= bookCopyPOPagePO.getTotalCount() %> 条记录，当前第 <%= bookCopyPOPagePO.getPageNum() %> / <%= bookCopyPOPagePO.getTotalPage() %> 页
    </div>
    <% } %>
</div>

<!-- 添加副本弹窗 - 修改后的版本 -->
<div id="addModal" class="modal">
    <div class="modal-content">
        <div class="modal-header">
            <h3>添加书籍副本</h3>
            <span class="close" onclick="closeModal('addModal')">&times;</span>
        </div>
        <form action="${pageContext.request.contextPath}/admin/bookcopy" method="post">
            <input type="hidden" name="method" value="addBookCopy">
            <div class="modal-body">
                <div class="form-group">
                    <label for="addISBN">选择书籍 *</label>
                    <select id="addISBN" name="ISBN" required>
                        <option value="">请选择要添加副本的书籍</option>
                        <% if (availableBooks != null && !availableBooks.isEmpty()) {
                            for (Book book : availableBooks) { %>
                        <option value="<%= book.getISBN() %>"><%= book.getBname() %> (ISBN: <%= book.getISBN() %>)</option>
                        <%   }
                        } else { %>
                        <option value="" disabled>（无可用上架书籍）</option>
                        <% } %>
                    </select>
                    <div id="addIsbnError" class="error-message"></div>
                </div>
                <div class="form-group">
                    <label for="addBarCode">副本编号 *</label>
                    <input type="text" id="addBarCode" name="barCode" required placeholder="输入6-20位字母数字组合">
                    <div id="addBarCodeError" class="error-message"></div>
                </div>
                <div class="form-group">
                    <label for="addPlace">存放位置 *</label>
                    <input type="text" id="addPlace" name="place" required placeholder="如：图书馆一楼A区">
                </div>
            </div>
            <div class="modal-footer">
                <button type="submit" class="btn">确认添加</button>
                <button type="button" class="btn-secondary" onclick="closeModal('addModal')">取消</button>
            </div>
        </form>
    </div>
</div>

<!-- 编辑副本弹窗 -->
<div id="editModal" class="modal">
    <div class="modal-content">
        <div class="modal-header">
            <h3>编辑书籍副本</h3>
            <span class="close" onclick="closeModal('editModal')">&times;</span>
        </div>
        <form action="${pageContext.request.contextPath}/admin/bookcopy" method="post">
            <input type="hidden" name="method" value="updateBookCopy">
            <input type="hidden" id="editBarCodeHidden" name="barCode">
            <div class="modal-body">
                <div class="form-group">
                    <label for="editBarCode">副本编号</label>
                    <input type="text" id="editBarCode" readonly style="background-color: #f5f5f5;">
                    <small class="form-text text-muted">副本编号不可修改</small>
                </div>
                <div class="form-group">
                    <label for="editISBN">ISBN</label>
                    <input type="text" id="editISBN" readonly style="background-color: #f5f5f5;">
                    <small class="form-text text-muted">ISBN不可修改</small>
                </div>
                <div class="form-group">
                    <label for="editPlace">存放位置 *</label>
                    <input type="text" id="editPlace" name="place" required placeholder="如：图书馆一楼A区">
                </div>
                <div class="form-group">
                    <label for="editStatus">状态 *</label>
                    <select id="editStatus" name="status" required>
                        <option value="1">可借</option>
                        <option value="0">借出</option>
                    </select>
                </div>
            </div>
            <div class="modal-footer">
                <button type="submit" class="btn">确认更新</button>
                <button type="button" class="btn-secondary" onclick="closeModal('editModal')">取消</button>
            </div>
        </form>
    </div>
</div>

<script>
    // 显示添加弹窗
    function showAddModal() {
        document.getElementById('addModal').style.display = 'block';
        // 清空表单
        document.getElementById('addISBN').value = '';
        document.getElementById('addBarCode').value = '';
        document.getElementById('addPlace').value = '';
        document.getElementById('addStatus').value = '1';
        document.getElementById('addIsbnError').textContent = '';
        document.getElementById('addBarCodeError').textContent = '';
    }

    // 显示编辑弹窗
    function showEditModal(barCode, isbn, place, status) {
        document.getElementById('editModal').style.display = 'block';
        document.getElementById('editBarCode').value = barCode;
        document.getElementById('editBarCodeHidden').value = barCode;
        document.getElementById('editISBN').value = isbn;
        document.getElementById('editPlace').value = place;
        document.getElementById('editStatus').value = status;

        // 如果是借出状态(0)，禁用状态选择
        var statusSelect = document.getElementById('editStatus');
        if (status == 0) {
            statusSelect.disabled = true;
            statusSelect.style.backgroundColor = '#f8f9fa';
            // 添加提示
            var statusGroup = statusSelect.parentNode;
            var existingTip = statusGroup.querySelector('.status-tip');
            if (!existingTip) {
                var tip = document.createElement('div');
                tip.className = 'status-tip';
                tip.textContent = '已借出的副本不能修改状态';
                statusGroup.appendChild(tip);
            }
        } else {
            statusSelect.disabled = false;
            statusSelect.style.backgroundColor = '';
            // 移除提示
            var statusGroup = statusSelect.parentNode;
            var existingTip = statusGroup.querySelector('.status-tip');
            if (existingTip) {
                existingTip.remove();
            }
        }
    }

    // 关闭弹窗
    function closeModal(modalId) {
        document.getElementById(modalId).style.display = 'none';

        // 如果是编辑弹窗，重置状态选择器
        if (modalId === 'editModal') {
            var statusSelect = document.getElementById('editStatus');
            statusSelect.disabled = false;
            statusSelect.style.backgroundColor = '';

            var statusGroup = statusSelect.parentNode;
            var existingTip = statusGroup.querySelector('.status-tip');
            if (existingTip) {
                existingTip.remove();
            }
        }
    }

    // 点击弹窗外部关闭弹窗
    window.onclick = function(event) {
        var addModal = document.getElementById('addModal');
        var editModal = document.getElementById('editModal');

        if (event.target == addModal) {
            addModal.style.display = 'none';
        }
        if (event.target == editModal) {
            editModal.style.display = 'none';
        }
    }

    // 全选/取消全选
    function toggleSelectAll() {
        var checkboxes = document.getElementsByClassName('copy-checkbox');
        var selectAllCheckbox = document.getElementById('selectAll');

        for (var i = 0; i < checkboxes.length; i++) {
            checkboxes[i].checked = selectAllCheckbox.checked;
        }
    }

    // 注销单个副本 - 修改为表单提交而不是直接跳转
    function cancelCopy(barCode) {
        if (confirm('确定要注销这个副本吗？注销后将无法借阅。')) {
            var form = document.createElement('form');
            form.method = 'post';
            form.action = '${pageContext.request.contextPath}/admin/bookcopy';

            var methodInput = document.createElement('input');
            methodInput.type = 'hidden';
            methodInput.name = 'method';
            methodInput.value = 'deleteBookCopy';

            var barCodeInput = document.createElement('input');
            barCodeInput.type = 'hidden';
            barCodeInput.name = 'barCode';
            barCodeInput.value = barCode;

            form.appendChild(methodInput);
            form.appendChild(barCodeInput);
            document.body.appendChild(form);
            form.submit();
        }
    }

    // 批量注销副本 - 修改为表单提交
    function batchCancel() {
        var selectedCopies = [];
        var checkboxes = document.getElementsByClassName('copy-checkbox');

        for (var i = 0; i < checkboxes.length; i++) {
            if (checkboxes[i].checked) {
                selectedCopies.push(checkboxes[i].value);
            }
        }

        if (selectedCopies.length === 0) {
            alert('请至少选择一个副本');
            return;
        }

        if (confirm('确定要注销选中的 ' + selectedCopies.length + ' 个副本吗？')) {
            var form = document.createElement('form');
            form.method = 'post';
            form.action = '${pageContext.request.contextPath}/admin/bookcopy';

            var methodInput = document.createElement('input');
            methodInput.type = 'hidden';
            methodInput.name = 'method';
            methodInput.value = 'batchDeleteBookCopy';
            form.appendChild(methodInput);

            // 添加所有选中的条码号
            for (var i = 0; i < selectedCopies.length; i++) {
                var barCodeInput = document.createElement('input');
                barCodeInput.type = 'hidden';
                barCodeInput.name = 'barCodes';
                barCodeInput.value = selectedCopies[i];
                form.appendChild(barCodeInput);
            }

            document.body.appendChild(form);
            form.submit();
        }
    }

    // 书籍选择事件处理（可选功能）
    function onBookSelect() {
        var select = document.getElementById('addISBN');
        var selectedOption = select.options[select.selectedIndex];

        if (selectedOption.value) {
            // 可以在这里添加额外的逻辑，比如显示书籍的详细信息
            console.log('选择了书籍：', selectedOption.text);
        }
    }

    // 页面加载完成后添加事件监听器
    document.addEventListener('DOMContentLoaded', function() {
        var isbnSelect = document.getElementById('addISBN');
        if (isbnSelect) {
            isbnSelect.addEventListener('change', onBookSelect);
        }
    });
</script>
</body>
</html>